package com.frxuexi.park2210.notice

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.frxuexi.lib_base.entity.NoticeBeanItem
import com.frxuexi.park2210.R
import com.frxuexi.park2210.databinding.ItemNoticeBinding

class NoticeAdapter:PagingDataAdapter<NoticeBeanItem,NoticeAdapter.MyViewHolder> (diff){
    companion object{
        val diff=object :ItemCallback<NoticeBeanItem>(){
            override fun areItemsTheSame(
                oldItem: NoticeBeanItem,
                newItem: NoticeBeanItem
            ): Boolean {
                return oldItem.noticeId==newItem.noticeId
            }

            override fun areContentsTheSame(
                oldItem: NoticeBeanItem,
                newItem: NoticeBeanItem
            ): Boolean {
                return oldItem==newItem
            }

        }
    }

    class MyViewHolder(itemView:View):ViewHolder(itemView){
        val binding:ItemNoticeBinding?=DataBindingUtil.bind(itemView)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val item = getItem(position)!!
        holder.binding?.apply {
            noticeTitle.text=item.noticeTitle
            noticeValue.text=item.noticeValue
            noticeUser.text=item.userId.toString()
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_notice, parent, false)
        return MyViewHolder(view)
    }


}